home *** CD-ROM | disk | FTP | other *** search
- package com.commerceone.util.queue;
-
- import com.commerceone.util.contract.Contract;
- import java.io.Serializable;
- import java.util.Enumeration;
- import java.util.Vector;
-
- public class Queue implements Serializable {
- public static final int DEFAULT_Q_SIZE = 128;
- protected int frontIndex = 0;
- protected int nextAvail = 0;
- protected int queueLen = 0;
- protected Vector vec = null;
-
- public Queue(int size) {
- this.vec = new Vector();
- this.vec.setSize(size);
- this.queueLen = size;
- }
-
- public synchronized Object peek() throws QueueEmptyException {
- if (this.isEmpty()) {
- throw new QueueEmptyException("Queue is empty");
- } else {
- return this.vec.elementAt(this.frontIndex);
- }
- }
-
- public Enumeration getElements() {
- return this.getElements(this.vec.size());
- }
-
- public synchronized int size() {
- int sz = (this.queueLen - this.frontIndex + this.nextAvail) % this.queueLen;
- Contract.ensure(sz >= 0);
- return sz;
- }
-
- public Enumeration getElements(int numEntries) {
- Vector v = new Vector();
- Object obj = null;
- Enumeration enum = this.vec.elements();
-
- int i;
- for(i = 0; i < numEntries && enum.hasMoreElements(); ++i) {
- obj = enum.nextElement();
- if (obj != null) {
- v.addElement(obj);
- } else {
- --i;
- }
- }
-
- v.setSize(i);
- return v.elements();
- }
-
- // $FF: renamed from: dq () java.lang.Object
- public synchronized Object method_0() throws QueueEmptyException {
- Object tmp = null;
- if (this.isEmpty()) {
- throw new QueueEmptyException("Queue is empty");
- } else {
- tmp = this.vec.elementAt(this.frontIndex);
- this.vec.setElementAt((Object)null, this.frontIndex);
- this.frontIndex = (this.frontIndex + 1) % this.queueLen;
- Contract.ensure(this.frontIndex >= 0);
- return tmp;
- }
- }
-
- // $FF: renamed from: q (java.lang.Object) void
- public synchronized void method_1(Object entry) throws QueueFullException {
- if (this.size() == this.queueLen - 1) {
- throw new QueueFullException("Queue is full");
- } else {
- this.vec.setElementAt(entry, this.nextAvail);
- this.nextAvail = (this.nextAvail + 1) % this.queueLen;
- Contract.ensure(this.nextAvail >= 0);
- }
- }
-
- public synchronized boolean isEmpty() {
- return this.frontIndex == this.nextAvail;
- }
- }
-